package com.qidianit.mes.production.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.common.util.Constant;
import com.qidianit.mes.pojo.Process;
import com.qidianit.mes.pojo.ProcessSteps;
import com.qidianit.mes.production.mapper.ProcessMapper;
import com.qidianit.mes.production.service.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author djl
 * @Time 2024/10/15 23:28
 */
@Service
public class ProcessServiceImpl implements ProcessService {
    @Autowired
    private ProcessMapper processMapper;
    @Override
    public MESResult queryProcess(String processId,String processName,Integer processStatus,Integer page, Integer limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Process> processes = processMapper.selectList(processId,processName,processStatus);
        PageInfo<Process> pageInfo = new PageInfo<>(processes);
        // 将pageInfo对象设置到qdResult中
        return MESResult.success(pageInfo);
    }

    @Override
    public MESResult addNewProcess(Process process) {
        if(processMapper.selectByProcessId(process.getProcessId()) == null){
            processMapper.addNewProcess(process);
            return MESResult.success(Constant.RESPONSE_STATUS_OK);
        }
        return MESResult.error(Constant.RESPONSE_STATUS_REPEAT);
    }

    @Override
    public MESResult deleteProcess(String processId) {
        return MESResult.success(processMapper.deleteProcess(processId));
    }

    @Override
    public MESResult countProcess() {
        return MESResult.success(processMapper.countProcess());
    }

    @Override
    public MESResult editProcess(Process process) {
        return MESResult.success(processMapper.editProcess(process));
    }

    @Override
    public MESResult reDelete(String[] processIds) {
        return MESResult.success(200,"OK",processMapper.reDelete(processIds));
    }

    @Override
    public MESResult queryAll() {
        return MESResult.success(processMapper.queryAll());
    }

    @Override
    public MESResult showByProcess(String processId) {
        return MESResult.success(processMapper.selectByProcessId(processId));
    }

}
